import { $get, $put } from '@js/request'
import { SeriesSchema } from '@src/components/schema/seriesCase'
import { ConditionSchema } from '@src/components/schema/condition'

export async function getSeriesListRequest (d: { condition: ConditionSchema[], page: number, limit: number, type: string, caseno_desc?: string }): Promise<{ list: SeriesSchema[], total: number }> {
  const params: { [k: string]: any } = {
    condition: JSON.stringify(d.condition),
    page: d.page,
    limit: d.limit,
    serieno_type: d.type
  }
  if (typeof d.caseno_desc === 'string' && d.caseno_desc.length > 0) {
    params.caseno_desc = d.caseno_desc
  }
  const res = await $get('/api/commission/caseserie', params)
  const list: SeriesSchema[] = res.data.list
  list.forEach((li, i) => {
    li.orderno = (d.page - 1) * d.limit + i + 1
  })
  return res.data
}

// 取消系列案
export async function deleteSeriesRequest (id: string): Promise<void> {
  const res = await $put(`/api/commission/caseserie/unserie/${id}`)
  return res.data
}
